package com.sumer.psychology.sharing.infrastructure.messaging.rabbitmq;

import com.sumer.psychology.common.port.adapter.messaging.Exchanges;
import com.sumer.psychology.common.port.adapter.messaging.rabbitmq.ExchangeListener;
import com.sumer.psychology.sharing.infrastructure.persistence.mongo.MongoSharedResourceRepository;

/**
 * 监听资源变更
 * <p/>
 * User: zhenguang.zhu
 * Date: 2014/11/3
 * Time: 15:13
 */
public class SharedResourceChangedListener extends ExchangeListener {
    private MongoSharedResourceRepository mongoSharedResourceRepository;

    public SharedResourceChangedListener(MongoSharedResourceRepository mongoSharedResourceRepository) {
        this.mongoSharedResourceRepository = mongoSharedResourceRepository;
    }

    @Override
    protected String exchangeName() {
        return Exchanges.DEFAULT_EXCHANGE_NAME;
    }

    @Override
    protected void filteredDispatch(String aType, String aTextMessage) {
        mongoSharedResourceRepository().change(aTextMessage);
    }

    @Override
    protected String[] listensTo() {
        return new String[]{"com.sumer.psychology.sharing.domain.model.SharedResourceChangedEvent"};
    }

    public MongoSharedResourceRepository mongoSharedResourceRepository() {
        return mongoSharedResourceRepository;
    }
}
